.TH PTHREAD_MUTEXATTR 3 LinuxThreads


.SH NAME
pthread_mutexattr_init, pthread_mutexattr_destroy, pthread_mutexattr_settype, pthread_mutexattr_gettype \- mutex creation attributes

.SH SYNOPSIS
.B #include <pthread.h>

.BI "int pthread_mutexattr_init(pthread_mutexattr_t *" attr ");"

.BI "int pthread_mutexattr_destroy(pthread_mutexattr_t *" attr ");"

.BI "int pthread_mutexattr_settype(pthread_mutexattr_t *" attr ", int " kind ");"

.BI "int pthread_mutexattr_gettype(const pthread_mutexattr_t *" attr ", int *" kind ");"

.SH DESCRIPTION

Mutex attributes can be specified at mutex creation time, by passing a
mutex attribute object as second argument to \fBpthread_mutex_init\fP(3).
Passing \fBNULL\fP is equivalent to passing a mutex attribute object with
all attributes set to their default values.

\fBpthread_mutexattr_init\fP initializes the mutex attribute object \fIattr\fP
and fills it with default values for the attributes.

\fBpthread_mutexattr_destroy\fP destroys a mutex attribute object, which
must not be reused until it is reinitialized. \fBpthread_mutexattr_destroy\fP
does nothing in the LinuxThreads implementation. 

LinuxThreads supports only one mutex attribute: the mutex kind, which
is either \fBPTHREAD_MUTEX_FAST_NP\fP for ``fast'' mutexes,
\fBPTHREAD_MUTEX_RECURSIVE_NP\fP for ``recursive'' mutexes,
or \fBPTHREAD_MUTEX_ERRORCHECK_NP\fP for ``error checking'' mutexes.
As the \fBNP\fP suffix indicates, this is a non-portable extension to the
POSIX standard and should not be employed in portable programs.

The mutex kind determines what happens if a thread attempts to lock a
mutex it already owns with \fBpthread_mutex_lock\fP(3). If the mutex is of
the ``fast'' kind, \fBpthread_mutex_lock\fP(3) simply suspends the calling
thread forever.  If the mutex is of the ``error checking'' kind,
\fBpthread_mutex_lock\fP(3) returns immediately with the error code
\fBEDEADLK\fP.  If the mutex is of the ``recursive'' kind, the call to
\fBpthread_mutex_lock\fP(3) returns immediately with a success return
code. The number of times the thread owning the mutex has locked it is
recorded in the mutex. The owning thread must call
\fBpthread_mutex_unlock\fP(3) the same number of times before the mutex
returns to the unlocked state.

The default mutex kind is ``fast'', that is, \fBPTHREAD_MUTEX_FAST_NP\fP.

\fBpthread_mutexattr_settype\fP sets the mutex kind attribute in \fIattr\fP
to the value specified by \fIkind\fP.

\fBpthread_mutexattr_gettype\fP retrieves the current value of the
mutex kind attribute in \fIattr\fP and stores it in the location pointed
to by \fIkind\fP.

.SH "RETURN VALUE"
\fBpthread_mutexattr_init\fP, \fBpthread_mutexattr_destroy\fP and
\fBpthread_mutexattr_gettype\fP always return 0.

\fBpthread_mutexattr_settype\fP returns 0 on success and a non-zero
error code on error.

.SH ERRORS

On error, \fBpthread_mutexattr_settype\fP returns the following error code:
.TP
\fBEINVAL\fP
\fIkind\fP is neither \fBPTHREAD_MUTEX_FAST_NP\fP nor \fBPTHREAD_MUTEX_RECURSIVE_NP\fP
nor \fBPTHREAD_MUTEX_ERRORCHECK_NP\fP

.SH AUTHOR
Xavier Leroy <Xavier.Leroy@inria.fr>

.SH "SEE ALSO"
\fBpthread_mutex_init\fP(3),
\fBpthread_mutex_lock\fP(3),
\fBpthread_mutex_unlock\fP(3).
